package cn.justforchris.system.controller;

import cn.justforchris.exception.BusinessException;
import cn.justforchris.system.dto.LoginDto;
import cn.justforchris.system.service.ILogininfoService;
import cn.justforchris.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILogininfoService loginInfoService;

    @PostMapping("/account")
    public JsonResult accountLogin(@RequestBody LoginDto loginDto){
            try {
                String token = loginInfoService.accountLogin(loginDto);
                return JsonResult.success(token);
            }catch (BusinessException e){
                return JsonResult.error(e.getMessage());
            }catch (Exception e){
                e.printStackTrace();
                return JsonResult.error();
            }
    }

}
